package array

import "math"

func minSubArrayLen(target int, nums []int) int {
	res := math.MaxInt32
	sum := 0
	i := 0
	subLength := 0
	for j := 0; j < len(nums); j++ {
		sum += nums[j]
		for sum >= target {
			subLength = j - i + 1
			if res >= subLength {
				res = subLength
			}
			sum -= nums[i]
			i++
		}
	}
	if res == math.MaxInt32 {
		return 0
	} else {
		return res
	}
}
